package com.kk.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;

import javax.persistence.*;
import java.util.Set;

@EqualsAndHashCode(callSuper = true) //@Data会生成equals和hashCode方法，这个注解作用：使用父类的equals和hashCode方法
@Data
@Entity
@Table(name = "user")
public class User extends BaseEntity{
    @NonNull
    private String username;
    @NonNull
    @JsonIgnore
    private String password;
    //用户的角色   一对多关系
    @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    @JoinTable(name = "user_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
//    @JsonIgnore
    private Set<Role> roles;

    //排序
    private int sort;
    @Transient//不在数据库中创建
    @JsonInclude(JsonInclude.Include.NON_NULL)//如果字段值为空则不序列化，即接口返回的数据不显示此字段
    private String token;

    public User() {
    }

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }
}

